#ifndef HAL_ADC_H
#define HAL_ADC_H

#include "hardware.h"
#define ADC_CHANNEL_COUNT 30

#define ADC_TEMP_ENABLE 1
#define AVCC_1P3_CHANNEL 27
#define TEMP_CHANNEL 28
#define VCC_1V2_CHANNEL 29

typedef struct _adc{
	uint8_t init : 1;
	uint8_t cmp  : 1;
	uint8_t seq  : 2;
	uint8_t start : 1;
	uint8_t ch_num;
	uint32_t valid;
	uint8_t aindex;
	uint8_t sarray[ADC_CHANNEL_COUNT];
	uint16_t value[ADC_CHANNEL_COUNT];
}ADC;

void adc_init(void);
void adc_start(void);

uint8_t adc_valid(void);

uint16_t get_adc_value(uint8_t ch);
uint16_t get_adc_1p3_value(void);
uint16_t get_adc_1v2_value(void);
uint16_t get_vcc_ref(void);

float adc_convert_vol(uint16_t v);

ADC* get_adc_obj(void);

#endif
